﻿#region License
//------------------------------------------------------------
// Copyright (c) Denis Vuyka.  All rights reserved.
// This source code is subject to terms and conditions of the 
// Microsoft Reciprocal License (Ms-RL) License for Carcass. 
// A copy of the license can be found in the License.txt file 
// at the root of this distribution. 
// By using this source code in any fashion, you are agreeing 
// to be bound by the terms of the 
// Microsoft Reciprocal License (Ms-RL) License
// You must not remove this notice from this software.
//------------------------------------------------------------
#endregion

using System;
using System.ComponentModel.Composition;
using System.Windows.Controls;
using Carcass.Events;
using Carcass.Messaging;
using Carcass.Presentation.Events;
using Carcass.Shell;

namespace DemoShell.Modules
{
  [Export(Carcass.GlobalContracts.PadView)]
  [PadViewMetadata(Name = "Right", Docking = Dock.Right)]
  public class TextPad1 : TextBox
  {
    public TextPad1()
    {
      this.Text = "Dummy text content #1";
    }
  }

  [Export(Carcass.GlobalContracts.PadView)]  
  [PadViewMetadata(Name = "Left", Docking = Dock.Left)]
  public class TextPad2 : TextBox, INotifyImportSatisfaction
  {
    [Import]
    private IEventAggregator eventAggregator = null;

    private SubscriptionToken subscriptionToken;

    public TextPad2()
    {
      this.Text = "Dummy text content #2";
    }

    #region INotifyImportSatisfaction Members

    public void ImportCompleted()
    {
      if (eventAggregator != null)
      {
        UserMessagePostedEvent messagePostedEvent = eventAggregator.GetEvent<UserMessagePostedEvent>();
        if (subscriptionToken != null)
          messagePostedEvent.Unsubscribe(subscriptionToken);

        subscriptionToken = messagePostedEvent.Subscribe(OnUserMessagePosted, ThreadOption.UIThread, false);
      }
    }

    private void OnUserMessagePosted(UserMessage message)
    {
      this.Text += Environment.NewLine + message.Text;
    }

    #endregion
  }

  [Export(Carcass.GlobalContracts.PadView)]
  [PadViewMetadata(Name="Bottom 1", Docking = Dock.Bottom, DockId = 0)]
  public class TextPad3 : TextBox
  {
    public TextPad3()
    {
      this.Text = "Dummy text content #3";
    }
  }

  [Export(Carcass.GlobalContracts.PadView)]
  [PadViewMetadata(Name = "Bottom 2", Docking = Dock.Bottom)]
  public class TextPad4 : TextBox
  {
    public TextPad4()
    {
      this.Text = "Dummy text content #4";
    }
  }

  [Export(Carcass.GlobalContracts.PadView)]
  [PadViewMetadata(Name = "Bottom 3", Docking = Dock.Bottom)]
  public class TextPad5 : TextBox
  {
    public TextPad5()
    {
      this.Text = "Dummy text content #5";
    }
  }
}